package conf

import (
	"fmt"
	"generalhandler/utils"
	"path"
)

type MQConfig struct {
	NsqdTcpAddresses []string `json:"nsqd_tcp_addresses"`
	NsqdLookupdAddresses []string `json:"nsq_lookupd_addresses"`
	LookupdPollInterval int `json:"lookupd_poll_interval"`

	HandlerName string `json:"handler_name"`

	LogTopic string `json:"log_topic"`
	MQTopic string `json:"mq_topic"`
	MQChannel string `json:"mq_channel"`

	NextHandlers []string `json:"next_handlers"`
}

var mqc *MQConfig
func MQConfigInstance() *MQConfig {
	return mqc
}

func LoadMQConf() {
	path := path.Join(utils.GetSelfBinDirPath(), "mq.config")
	if err := utils.LoadJsonFromFile(path, &mqc); nil != err {
		panic(fmt.Sprintf("failed to load mq config, cuz %s", err.Error()))
	}
}
